package com.wind;

import com.google.gson.Gson;
import com.wind.user.model.UserVO;
import com.wind.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2015/12/21.
 */
@Controller
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping(produces = "text/plain;charset=UTF-8",value = "/UserLogin",method = RequestMethod.POST)
    @ResponseBody
    public String login(HttpServletRequest request){
        String userId = request.getParameter("userId");
        UserVO userVO;
        userVO= userService.getUserInfo(userId);
        if (userVO != null&&userVO.getPassword().equals(request.getParameter("password"))){
            userVO.setMessage("success");
        }else {
            userVO = new UserVO();
            userVO.setMessage("error");
        }
        String json= new Gson().toJson(userVO);
        System.out.println(json);
        return json;
    }
}

